package com.project.service;

import com.project.bean.UserBean;
import com.project.dao.IUserDao;
import com.project.dao.impl.UserDaoImpl;
import com.project.server.Request;
import com.project.server.Response;
import com.project.server.Servlet;
import com.project.util.DaoFactory;
import com.project.util.WebServlet;

import java.util.List;

@WebServlet("findAll")
public class FindAllService implements Servlet {
    private IUserDao dao = (IUserDao) DaoFactory.getDao("IUserDao");
    public void service(Request req, Response resp){
        List<UserBean> list = dao.findAll();

        String str ="<table border='1' width='80%'>";
        str+="<thead><tr><th>用户名</th><th>密码</th><th>生日</th><th>操作</th></tr></thead>";

        str+="<tbody>";
        for (UserBean user:list) {
            str += "<tr><td>"+user.getName()+"</td>"+
                    "<td>"+user.getPassword()+"</td>"+
                    "<td>"+user.getBirthday()+"</td>"+
                    //用超链接a href输入跳转的地址。
                    "<td><a href='del?id="+user.getId()+"'>删除</a>"+
                    "<a href='findById?id="+user.getId()+"'>修改</a></td></tr>";
        }

        str += "</tbody></table>";
        resp.sendMessage(str);
    }
}
